package com.easygem.front.service.imp;

import com.easygem.common.error.SystemCodeEnum;
import com.easygem.common.error.SystemException;
import com.easygem.common.model.front.DepartmentStats;
import com.easygem.common.response.ActiveUser;
import com.easygem.common.vo.front.DepartmentStatsVo;
import com.easygem.front.converter.DepartmentStatsConverter;
import com.easygem.front.mapper.DepartmentStatsMapper;
import com.easygem.front.service.DepartmentStatsService;
import com.easygem.front.service.base.AbstractServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author luoxi
 * @version 1.0
 * @className DepartmentStatsServiceImpl
 * @Description 部门统计数据业务层接口的实现
 * @date 2024/12/23 16:05
 */
@Service
public class DepartmentStatsServiceImpl extends AbstractServiceImpl<DepartmentStatsMapper, DepartmentStats,Integer> implements DepartmentStatsService {
    @Autowired
    private DepartmentStatsMapper departmentStatsMapper;

    @Override
    public DepartmentStatsVo edit() throws SystemException {
        //获得到登录后的用户信息，通用方式
        ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
        if (activeUser.getUser().getType()==0){
            DepartmentStats departmentStats = departmentStatsMapper.selectByDepartmentId(activeUser.getUser().getAccountName());
            if(departmentStats==null){
                throw new SystemException(SystemCodeEnum.PARAMETER_ERROR,"统计中心信息不存在");
            }
            DepartmentStatsVo departmentStatsVo = DepartmentStatsConverter.converterToDepartmentStatsVo(departmentStats);
            return departmentStatsVo;
        }
        return null;
    }
}
